import {fileURLToPath, URL} from 'node:url'
import path from "path";
import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
// 根据当前工作目录中的 `mode` 加载 .env 文件
// 第二个参数：process.cwd()表示返回运行当前脚本的工作目录的路径（current work directory）
// 设置第三个参数为 '' 来加载所有环境变量，而不管是否有 `VITE_` 前缀。

import veauryVitePlugins from 'veaury/vite/esm/index.mjs'

// https://vitejs.dev/config/
export default () => defineConfig({
    base: './',
    plugins: [
        createSvgIconsPlugin({
          iconDirs: [path.resolve(process.cwd(), "src/assets/svgs")],
          // 指定symbolId格式
          symbolId: "[name]",
          customDomId: "turing-planet-svgs", // 避免多项目互相影响
        }),
        // vue(),
        veauryVitePlugins({
            type: 'vue',
        }),
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    server: {
        proxy: {
            "/PeachBanquet/backend/api/": {
                target: 'https://aimeta.huilan.com:32108/PeachBanquet/backend/api/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/PeachBanquet\/backend\/api/, "")
            },
            "/2dWebApi": {
                target: 'https://aimeta.huilan.com:32109/2dWebApi/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/2dWebApi/, "")
            },
            "/api": {
                target: 'https://aimeta.huilan.com:32108/api/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, "")
            },
            "/aihuman/api/aihuman-config": {
                target: 'https://aimeta.huilan.com:32108/aihuman/api/aihuman-config/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/aihuman\/api\/aihuman-config/, "")
            },
            "/aihuman/api/aihuman-coreBusiness": {
                target: 'https://aimeta.huilan.com:32108/aihuman/api/aihuman-coreBusiness/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/aihuman\/api\/aihuman-coreBusiness/, "")
            },
            "/aihuman/api/aihuman-engine": {
                target: 'https://aimeta.huilan.com:32108/aihuman/api/aihuman-engine/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/aihuman\/api\/aihuman-engine/, "")
            },
            "/aimeetback/api": {
                target: 'https://aimeta.huilan.com:32108/aimeetback/api/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/aimeetback\/api/, "")
            },
            "/perApi/offer": {
                target: 'https://aimeta.huilan.com:32108/perApi/offer/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/perApi\/offer/, "")
            },
            "aihuman/minioFile/": {
                target: 'https://aimetacdn.huilan.com/aihuman/minioFile/',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/aihuman\/minioFile/, "")
            },
        },
        hmr: {
            overlay: true,
            // 解决热更新不同步的问题
            port: 443
          },
        host:'0.0.0.0',
        port: 5173,
        open: true
    },
    build: {
        rollupOptions: {
            input: {
                main: './src/main.ts',// 入口文件main.ts
                index:'./index.html'
            }
       },
       target:['edge90','chrome90','firefox90','safari15']
    },
})